package khtn.mylocation;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class SQLiteHelper extends SQLiteOpenHelper {

	public static final String TABLE_LOCATION = "locations";
	public static final String LOCATION_ID = "id";
	public static final String LOCATION_NAME = "name";
	public static final String LOCATION_DESCRIPTION = "description";
	public static final String LOCATION_CATEGORY = "category";
	public static final String LOCATION_LAT = "lat";
	public static final String LOCATION_LNG = "lng";

	private static final String DATABASE_NAME = "mylocation.db";
	private static final int DATABASE_VERSION = 2;
	
	public SQLiteHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);

	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		String  locationTableQuery = "create table " + TABLE_LOCATION + "( "
										+ LOCATION_ID + " integer primary key autoincrement, "
										+ LOCATION_NAME + " text not null, "
										+ LOCATION_DESCRIPTION + " text null, "
										+ LOCATION_CATEGORY + " integer not null, " 
										+ LOCATION_LAT + " real not null, "
										+ LOCATION_LNG + " real not null);";
		db.execSQL(locationTableQuery);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_LOCATION);
		onCreate(db);
	}

}
